package xyz.lilei123.test;


import xyz.lilei123.test.dao.AccountDao;
import xyz.lilei123.test.pojo.Account;
import xyz.lilei23.framework.annotation.AutoWired;
import xyz.lilei23.framework.annotation.Service;
import xyz.lilei23.framework.annotation.Transactional;

/**
 * @author 应癫
 */
@Service
public class TransferServiceImpl implements TransferService {

    @AutoWired
    private AccountDao accountDao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney() - money);
        to.setMoney(to.getMoney() + money);

        accountDao.updateAccountByCardNo(to);
        int c = 1 / 0;
        accountDao.updateAccountByCardNo(from);
    }
}
